using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Protocol;
using System;
namespace MicroMsg.Scene
{
	public class NetSceneSearchContact : NetSceneBaseEx<SearchContactRequest, SearchContactResponse, SearchContactRequest.Builder>
	{
		private const string TAG = "NetSceneSearchContact";
		public void doScene(string account)
		{
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.UserName = Util.toSKString(account);
			this.mSessionPack.mConnectMode = 2;
			this.mSessionPack.mCmdUri = "/cgi-bin/micromsg-bin/searchcontact";
			base.endBuilder();
		}
		protected override void onFailed(SearchContactRequest request, SearchContactResponse response)
		{
			EventCenter.postEvent(EventConst.ON_NETSCENE_SEARCHCONTACT_ERR, -800000, null);
		}
		protected override void onSuccess(SearchContactRequest request, SearchContactResponse response)
		{
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			if (ret == RetConst.MM_OK)
			{
				Log.smethod_5("NetSceneSearchContact", "success. username = " + response.UserName);
				EventCenter.postEvent(EventConst.ON_NETSCENE_SEARCHCONTACT_SUCCESS, new SearchContactInfo
				{
					UserName = response.UserName.String,
					NickName = response.NickName.String,
					PYInitial = response.PYInitial.String,
					QuanPin = response.QuanPin.String,
					Sex = response.Sex,
					ImgBuf = response.ImgBuf.Buffer.ToByteArray(),
					Province = response.Province,
					City = response.City,
					Signature = response.Signature,
					PersonalCard = response.PersonalCard,
					VerifyFlag = response.VerifyFlag,
					VerifyInfo = response.VerifyInfo,
					SnsFlag = response.SnsUserInfo.SnsFlag,
					SnsBGImgID = response.SnsUserInfo.SnsBGImgID,
					SnsBGObjectID = response.SnsUserInfo.SnsBGObjectID,
					strAlias = response.Alias,
					MyBrandList = response.MyBrandList
				}, null);
				return;
			}
			Log.smethod_5("NetSceneSearchContact", "failed,   ret = " + ret);
			EventCenter.postEvent(EventConst.ON_NETSCENE_SEARCHCONTACT_ERR, ret, null);
		}
		private static void onHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_SEARCHCONTACT_SUCCESS)
			{
				Log.smethod_5("NetSceneSearchContact", "(1/1)on success");
			}
		}
		public static void testSearchContact()
		{
			EventWatcher eventWatcher = new EventWatcher(null, null, new EventHandlerDelegate(NetSceneSearchContact.onHandler));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SEARCHCONTACT_SUCCESS, eventWatcher);
			ServiceCenter.sceneSearchContact.doScene("halen5064");
		}
	}
}
